package bank.soap.server;

import java.io.IOException;

import javax.jws.WebParam;
import javax.jws.WebService;

import bank.Account;
import bank.InactiveException;
import bank.OverdrawException;
import bank.local.LocalBank;

@WebService
public class BankServiceImpl implements BankService{
	private LocalBank bank;
	
	public BankServiceImpl() {
		bank = new LocalBank();
	}

	public void deposit(@WebParam(name = "number") String number, @WebParam(name = "amount") double amount) throws IllegalArgumentException, InactiveException, IOException {
		Account account = bank.getAccount(number);
		account.deposit(amount);
	}
	
	public void withdraw(@WebParam(name = "number") String number, @WebParam(name = "amount") double amount) throws IllegalArgumentException, OverdrawException, InactiveException, IOException {
		Account account = bank.getAccount(number);
		account.withdraw(amount);
	}
	
	public void transfer(@WebParam(name = "from") String from, @WebParam(name = "to") String to, @WebParam(name = "amount") double amount) throws IllegalArgumentException, OverdrawException, InactiveException, IOException {
		Account accfrom= bank.getAccount(from);
		Account accto = bank.getAccount(to);

		bank.transfer(accfrom, accto, amount);
	}
	
	public String createAccount(@WebParam(name = "owner") String owner) throws IOException {
		return bank.createAccount(owner);
	}

	public boolean removeAccount(@WebParam(name = "number") String number) throws IOException {
		return bank.removeAccount(number);
	}

	public Object[] getAccountNumbers() {
		return bank.getAccountNumbers().toArray();
	}

	public String getOwner(@WebParam(name = "number") String number) throws IOException {
		Account account = bank.getAccount(number);
		return account.getOwner();
	}

	public boolean isActive(@WebParam(name = "number") String number) throws IOException {
		Account account = bank.getAccount(number);
		return account.isActive();
	}

	public double getBalance(@WebParam(name = "number") String number) throws IOException {
		Account account = bank.getAccount(number);
		return account.getBalance();
	}

}
